#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

Mat src, dst, gray_src;

int main() {
  src = imread("../images/10.jpeg");
  if (src.empty()) {
    cout << "could not load image.." << endl;
    return -1;
  }
  namedWindow("opencv setup demo", CV_WINDOW_AUTOSIZE);
  imshow("opencv setup demo", src);

  char input[] = "input";
  char output[] = "output";
  // namedWindow(input, CV_WINDOW_AUTOSIZE);
  namedWindow(output, CV_WINDOW_AUTOSIZE);

  //　中值滤波
  Mat moutput;
  medianBlur(src, moutput, 3);
  cvtColor(moutput, moutput, CV_BGR2GRAY);

  // 霍夫圆检测
  vector<Vec3f> pcircle;
  HoughCircles(moutput, pcircle, CV_HOUGH_GRADIENT, 1, 10, 100, 46, 5, 100);
  src.copyTo(dst);
  std::cout << "size: " << pcircle.size() << endl;
  for (size_t i = 0; i < pcircle.size(); i++) {
    std::cout << "11" << endl;
    Vec3f cc = pcircle[i];
    circle(dst, Point(cc[0], cc[1]), cc[2], Scalar(0, 0, 255), 2, LINE_AA);
    circle(dst, Point(cc[0], cc[1]), 2, Scalar(155, 2, 155), 2, LINE_AA);
  }
  imshow(output, dst);

  waitKey(0);
  return 0;
}